package com.admin.service.admin_operate_service;


import com.admin.dao.adminlogindao.AdminDaoImpl;
import com.admin.dao.adminlogindao.AdminDaoInf;
import com.utils.DBUtil;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * 管理员操作功能实现类
 */
public class AdminOperateServiceImpl implements AdminOperateService {
    private AdminDaoInf adminDao=new AdminDaoImpl();

    @Override
    public boolean returnBookById(String bookId,String idCard) {
        boolean bool=false;
        Connection conn = null;
        try {
            conn = DBUtil.getConn();
            conn.setAutoCommit(false);
            String sql = "update borinfo set state='已归还' where bookid=? and borid=(select userid from borrower where idcard=?)";
            bool=adminDao.returnBookById(sql, conn,bookId,idCard);
            conn.commit();
        } catch (SQLException e) {
            e.printStackTrace();
            try {
                conn.rollback();
            } catch (SQLException throwable) {
                throwable.printStackTrace();
            }
        } finally {
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
        return bool;
    }
}
